/**
 * 
 */
package br.unifor.mia.cd.middleware.arcademis.marshalable;


/**
 * Fábrica de mecanismos de serialização.
 * @author landim
 *
 */
public class DefaultMarshallerMechanismFactory implements
		MarshallerMechanismFactory {

	/**
	 * <p>É retornado um {@link MarshallerInterfaceMechanism} </p>
	 * 
	 * @see br.unifor.mia.cd.middleware.arcademis.marshalable.MarshallerMechanismFactory#createMarshall()
	 */
	public MarshallerMechanism createMarshall() {
		return MarshallerInterfaceMechanism.getInstance();
	}

	/**
	 * <p>Se o objeto for do tipo {@link arcademis.Marshalable}, então é retornado <br>
	 * um {@link MarshallerInterfaceMechanism}. </p>
	 * 
	 * <p> Se a classe do objeto for anotada com {@link Marshalable}, <br>
	 * então é retornado um {@link MarshallerAnnotationMechanism} </p>
	 * 
	 * @see br.unifor.mia.cd.middleware.arcademis.marshalable.MarshallerMechanismFactory#createMarshall(java.lang.Object)
	 */
	public MarshallerMechanism createMarshall(Object obj) {
		MarshallerMechanism result = null;
		if (obj != null) {
			if (obj instanceof arcademis.Marshalable) {
				result = MarshallerInterfaceMechanism.getInstance();
			} else if (obj.getClass().isAnnotationPresent(Marshalable.class)) {
				result = MarshallerAnnotationMechanism.getInstance();
			}
		}
		return result;
	}

}
